import java.util.Scanner;
class Human extends Player {
    private static final int MAX_CHANGES = 4;
    private static final int HAND_SIZE = 5;
	Human(int startamount) {
		super(startamount);
	}

	public int[] picks() {
		@SuppressWarnings("resource")
		Scanner s = new Scanner(System.in);
		String input = "";
		int changes;
		System.out.println("Make sure others are not looking and press 'r'");
		while (!input.equals("r")) {
            input = s.next();
        }
		System.out.println("Your cards: " + getHand().toString());
		System.out.println("How many cards you want to change? 0-4");
		changes = s.nextInt();
		while (changes < 0 || changes > MAX_CHANGES) {
			System.out.println("Choose between 0-4");
			changes = s.nextInt();
		}
		int[] result = new int[changes];
		if (changes == 0) {
            return result;
        }
		int current;
		System.out.println("Now pick " + Integer.toString(changes) + " distinct numbers from 0-4 (from left to right)");
		for (int i = 0; i < changes; i++) {
			current = s.nextInt();
			while (current < 0 || current > HAND_SIZE - 1 || find(current, result, i)) {
				System.out.println("Choose between 0-4 (distinct!)");
				current = s.nextInt();
			}
			result[i] = current;
		}
		return result;
	}
	
	public int getDecision (int maxbet, boolean allIn) throws PokerException {
	    Scanner s = new Scanner(System.in);
	    int choice;
	    if (allIn) {
	        System.out.println("Other player went all-in, press 1 to go all-in, press 2 to fold");
	        choice = s.nextInt();
	        if (choice == 1) {
	            int bet = getCash();
	            addToMyBet(bet);
	            addToCash(-bet);
	            return bet;
	        }
	        else if (choice == 2) {
	            fold();
	            return -1;
	        }
	        else  {
	            System.out.println("Well done... Forced fold");
	            fold();
	            return -1;
	        }
	    }
	    if (maxbet == myBet()) {               // case 1: check/bet/fold
	        System.out.println("1 - check, 2 - bet, 3 - fold");
    	    choice = s.nextInt();
    	    if (choice == 1) {
    	     //   check();
    	        return 0;
    	    }
    	    else if (choice == 2) {
    	        System.out.println("How much to bet?"); //BET
    	        int bet = s.nextInt();
    	        if (bet <= 0) {
    	            System.out.println("Clever... Forced check");          // na za duzy bet go all in
    	         //   check();
    	            return 0;
    	        }
    	        else if (bet >= getCash()) {
    	            bet = getCash();
    	            addToMyBet(bet);
    	            addToCash(-bet);
    	            return bet;
    	        }
    	        else {
    	       //     bet();
    	            addToMyBet(bet);
    	            addToCash(-bet);           // tak wolno w javie?
    	            return bet;
    	        }
    	    }
    	    else if (choice == 3) {
    	        fold();
    	        return -1;
    	    }
    	    else {
    	        System.out.println("You are not the sharpest tool in the shed, are you? Forced check");
    	     //   check();
    	        return 0;
    	    }
	    }
	    else if (maxbet > myBet()) {           // case 2: call/raise/fold
	        System.out.println("1 - call, 2 - raise, 3 - fold");
            choice = s.nextInt();
            int bet;
            if (choice == 1) {
                if (maxbet - myBet() <= getCash()) {
              //      check();
                    bet = maxbet - myBet();
                    addToMyBet(bet);
                    addToCash(-bet);
                    return bet;
                }
                else {                  // too little cash for call
            //        check();
                    bet = getCash();
                    addToMyBet(bet);
                    addToCash(-bet);
                    return bet;
                }
            }
            else if (choice == 2) {
                System.out.println("Current bet is " + Integer.toString(maxbet - myBet()) + ", how much to raise?"); //BET
                bet = s.nextInt();
                if (bet >= getCash()) {
                    bet = getCash();
                    addToMyBet(bet);
                    addToCash(-bet);
                    return bet;
                }
                else {
                    if (bet < maxbet - myBet()) {
                        System.out.println("Clever... Forced fold");
                        fold();
                        return -1;
                    }
                    else if (bet == maxbet - myBet()) {
                        System.out.println("You meant call, right?");
                      //  check();
                        addToMyBet(bet);
                        addToCash(-bet);
                        return bet;
                    }
                    else {              // bet > maxbet - myBet() - proper raise
               //         bet();
                        addToMyBet(bet);
                        addToCash(-bet);
                        return bet;
                    }
                }
            }
            else if (choice == 3) {
                fold();
                return -1;
            }
            else {
                System.out.println("You are not the sharpest tool in the shed, are you? Forced fold");
                fold();
                return -1;
            }	        
	    }
	    else {
	        throw new PokerException("Error during betting");
	    }
	}

}
